import axios from './index'
import { userAPI, dataAPI, systemAPI } from './cefsharp'
import cefSharpAdapter from '@/util/cefsharp'
const isCEFSharp = () => cefSharpAdapter.checkEnvironment()
const api = {
    http: axios,
    cefsharp: {
        user: userAPI,
        data: dataAPI,
        system: systemAPI,
        call: (methodName, params = {}) =>
            cefSharpAdapter.callDbMethod(methodName, params),
        isAvailable: isCEFSharp
    },
    smart: {
        getUserInfo: (params = {}) => {
            return isCEFSharp()
                ? userAPI.getUserInfo(params)
                : axios.get('/user/info', { params })
        },
        login: (params = {}) => {
            return isCEFSharp()
                ? userAPI.login(params)
                : axios.post('/user/login', params)
        },
        getDataList: (params = {}) => {
            return isCEFSharp()
                ? dataAPI.getList(params)
                : axios.get('/data/list', { params })
        },
        saveData: (params = {}) => {
            return isCEFSharp()
                ? dataAPI.save(params)
                : axios.post('/data/save', params)
        }
    }
}
export default api
